package com.kobe.algorithm.leetcode.case3;

import java.util.HashMap;
import java.util.Map;

public class Solution2 {

    public int lengthOfLongestSubstring(String s) {

        Map<Character,Integer> cache = new HashMap<Character,Integer>();
        int maxlength = 0;
        for(int i = 0;i < s.length(); i++){
            int rightIndex = i;
            while(rightIndex < s.length() && cache.get(s.charAt(rightIndex)) == null ){
                cache.put(s.charAt(rightIndex),1);
                rightIndex++;
            }
            if(maxlength< rightIndex -i) {
                maxlength = rightIndex-i;
            }
            cache.clear();
        }
        return maxlength;
    }
}
